﻿namespace _01_单例模式;

public class Singleton_Thread
{

    private Guid _guid;

    private static Singleton_Thread? _instance;

    private static object _lock = new object();

    private Singleton_Thread()
    {
        _guid = Guid.NewGuid();
    }

    public static Singleton_Thread CreateInstance()
    {
        if (_instance is null)
        {
            lock (_lock)
            {
                return _instance ??= new Singleton_Thread();
            }
        }
        return _instance;
    }

    public void GetId()
    {
        Console.WriteLine(_guid);
    }

    public Guid GetGuid() => _guid;
}